#pragma once

#include "Node.h"
#include <map>
#include <string>

using namespace std;

namespace Huffman {

	class Tree
	{
	public:		
		static Node* NYT;
		static Node* EOC;
		int itCounter;

		Tree(void);
		~Tree(void);

		Node* findNode(char symbol);		

		void updateTreeVitter(char symbol);
		Node* slideAndIncrement(Node* n);
		Node* slideHigherThanLeafNodesWithWeight(Node* n, unsigned long weight);
		Node* slideHigherThanNodesWithWeight(Node* n, unsigned long weight);
		Node* slideInternalNode(Node* n, unsigned long weight);
		void swapNodes(Node* node1, Node* node2);	
		void printOnConsole();
		string getStrFromNode(Node* );

		void setRoot(Node* n);
		Node* getRoot() const;

		void setMaxAllowedWeight(unsigned long weight);
		unsigned long getMaxAllowedWeight();

		void freezeTree();

	private:		
		void checkWeight();
		Node* slide(Node* currentNode, Node* nextNode);

		std::map<char, Node*> nodeMap;
		Node* root;
		int idCounter;

		void displayNode();
		int getId(Node* n);

		bool freeze;
		unsigned long maxAllowedWeight;
	};
}
